

let reduceDmg = {
    physics: 106,
    pount: 106,
    cut: 106,
    thorn: 106,
    magic: 118,
    fire: 130,
    thunder: 98,
    holy: 118,
    tenacity: 100
}

let dk = {
    immune: 223,   
    robust: 254,  
    dead: 168, 
    san: 200,  
}


let Items = [
    {
        type: "head",
        name: "test",
        weight: 11.2,
        reduceDmg: {
            physics: 12.6,
            pount: 11,
            cut: 13.2,
            thorn: 12.1,
            magic: 9.2,
            fire: 12.2,
            thunder: 10,
            holy: 10.2,
            tenacity: 14
        },
        dk: {
            immune: 22,   
            robust: 24,  
            dead: 10, 
            san: 16,  
        }
    },
    {
        type: "body",
        name: "大山羊",
        weight: 26.5,
        reduceDmg: {
            physics: 20.4,
            pount: 20.2,
            cut: 18.3,
            thorn: 18.3,
            magic: 13.3,
            fire: 13.5,
            thunder: 14.9,
            holy: 12.8,
            tenacity: 47
        },
        dk: {
            immune: 71,   
            robust: 83,  
            dead: 46, 
            san: 55,  
        }
    }
]


let normalHeadItems = []

Items.forEach(armor => {
    let {weight, reduceDmg, dk} = armor
    let item = {...armor}
    let {physics,pount,cut,thorn,magic,fire,thunder,holy,tenacity} = reduceDmg
    let averagedmgReduceK = (physics+pount+cut+thorn+magic+fire+thunder+holy) / 8
    let dmgReduceK = averagedmgReduceK / weight
    item.dmgReduceK = dmgReduceK
    item.tenacityK = tenacity / weight
    let {immune,robust,dead,san} = dk
    item.dkQ = ((immune+robust+dead+san)/4)/weight
    normalHeadItems.push(item)
})

console.log(normalHeadItems.sort((a,b) => b.dmgReduceK - a.dmgReduceK));

let weapon = [
    {
        name:"巨剑",
        attack: 790,
    },
    {
        name:"短弯刀",
        attack: 540,
    },
    {
        name:"土龙鳞",
        attack: 370,
        fire: 220
    },
    {
        name:"夜火",
        attack: 183,
        magic: 151,
        fire: 141,
    }
]

weapon.forEach(wea => {
    let attack = calcDef(wea.attack, 110)
    let magic = calcDef(wea.magic || 0, 110)
    let fire = calcDef(wea.fire || 0, 110)

    let res = attack + fire + magic
    wea.point = res
})

console.log(weapon.sort((a,b) => b.point - a.point));



function calcDef(attack, def) {
    if(attack == 0) {return 0}
    if(def < 0.125*attack) {
        return 0.9 * attack
    } else if (def < 0.4*attack) {
        return (-0.8/121*((attack/def-8)*(attack/def-8))+0.9)*attack
    } else if (def < attack) {
        return (-0.4/3*((attack/def-2.5)*(attack/def-2.5))+0.7)*attack
    } else if (def < attack*8) {
        return (19.2/49*((attack/def-0.125)*(attack/def-0.125))+0.1)*attack
    } else {
        return 0.1 * attack
    }
}